<?php

uses('sanitize');

class Html2Helper extends Helper {
    var $helpers = array('Html');
    var $components = array('RequestHandler');
    
   /* function __call($method, $params) {
        return $this->view->controller->{$this->component}->$method($params);
    }*/
    
    function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
		//add form with post method thans to javascript only if confifmMessage present
		
		if ($confirmMessage) {
			$confirmMessage = str_replace("'", "\'", $confirmMessage);
			$confirmMessage = str_replace('"', '\"', $confirmMessage);
			$htmlAttributes['onclick']="if (confirm('$confirmMessage')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = this.href;f.submit(); };return false;";
		}
		$output = $this->Html->link($title, $url, $htmlAttributes, null, $escapeTitle, $return);
		return $this->output($output, $return);
	}
	
	function substr($str, $len = 100, $clean = true){
		
		if($clean){
			//$str = $clean($str);
			//remove html tags : 'secure' on php5
			$str = strip_tags($str);
		}
		
		if(strlen($str) > $len)
			$str = substr($str, 0, $len) . ' ...' ;
		return $this->output($str);
	}
	
	function gravatar_url($email = null){
		$size = '60';
		$default = '';
		$grav_url = 'http://www.gravatar.com/avatar.php?'.
					'gravatar_id='.md5($email).
					'&amp;default='.urlencode($default).
					'&amp;size='.$size;
		return $grav_url;
	}

}

?>
